package com.east.controller;

import com.east.dto.ActivityDTO;
import com.east.query.ActivityQuery;
import com.east.result.Result;
import com.east.service.ActivityService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/activity/")
@EnableMethodSecurity
public class ActivityController {
    @Resource
    private ActivityService activityService;

    /**
     * 根据条件查询活动信息
     *
     * @param currentPage
     * @param pageSize
     * @param activityQuery 查询条件
     * @return
     */
    @GetMapping("/searchList")
    public Result searchActivityList(
            @RequestParam(value = "currentPage", defaultValue = "1", required = false) Integer currentPage,
            @RequestParam(value = "pageSize", defaultValue = "8", required = false) Integer pageSize,
            ActivityQuery activityQuery) {
        System.out.println(activityQuery);
        return activityService.searchActivityList(currentPage, pageSize, activityQuery);
    }

    // todo
    @PostMapping("/add")
    @PreAuthorize(value = "hasAuthority('activity:add')")
    public Result addActivity(@RequestBody ActivityDTO activityDTO) {
        return activityService.addActivity(activityDTO);
    }

    @GetMapping("info/{id}")
    public Result activityInfo(@PathVariable("id") Integer id) {
        return activityService.activityInfo(id);
    }

    @PreAuthorize(value = "hasAuthority('activity:edit')")
    @PutMapping("update")
    public Result activityUpdate(@RequestBody ActivityDTO activityDTO) {
        return activityService.update(activityDTO);
    }

    /**
     * 根据id数组批量删除用户
     *
     * @param ids 用户id数组
     * @return
     */
    @PreAuthorize(value = "hasAuthority('activity:delete')")
    @PostMapping("batchDeleteUserByIds")
    public Result batchDeleteActivityByIds(@RequestBody Integer[] ids) {
        return activityService.deleteUserByIds(ids);
    }

    @GetMapping("onGoingActivity")
    public Result getOnGoingActivity() {
        return activityService.getOnGoingActivity();
    }
}
